package com.yanqu.road.server.manger;

import com.yanqu.road.dao.impl.servercenter.PlatformPolicyDaoImpl;
import com.yanqu.road.entity.servercenter.PlatformPolicy;
import com.yanqu.road.server.TempMgr;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：zfr
 * @date ：2021/11/30 11:49
 */
public class PlatformPolicyMgr extends TempMgr {
    private static Map<Integer, PlatformPolicy> platformPolicyMap = new ConcurrentHashMap<>();

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        platformPolicyMap = new PlatformPolicyDaoImpl().getPlatformPolicyMap();
        return true;
    }

    public static PlatformPolicy getPlatformPolicy(int channelId) {
        PlatformPolicy platformPolicy = platformPolicyMap.get(channelId);
        if (platformPolicy != null) {
            return platformPolicy;
        } else {
            return getDefaultPlatformPolicy();
        }
    }

    public static PlatformPolicy getDefaultPlatformPolicy() {
        return getPlatformPolicy(0);
    }

    @Override
    public boolean stop() {
        return false;
    }
}
